package sorter;

import java.rmi.Naming;
import java.util.ArrayList;

import sort.ISortFactory;
import sort.ListJoiner;
import sort.SorterThread;

@SuppressWarnings("rawtypes")
public class SortClient {
	
	private static final String HOST = "localhost";
	private static int amountOfValues = 100000;
	private static int amountOfThreads = 15;
	
	private ListJoiner ListJoiner;
	
	public SortClient(){
		
	}
	
	public void main(String args[]){
		Comparable[] sortArray = generateRandomList(amountOfValues, Integer.class);
		ListJoiner = new ListJoiner();
		sort(sortArray);
	}
	
	private Comparable[] generateRandom(int naamInt, Class klassenaam){
		Comparable[] random = null;
		//some code to generate random
		return random;
	}
	
	private Comparable[] generateRandomIntegers(int naamInt){
		Comparable[] randomIntegers = null;
		//some code to generate random Integers
		return randomIntegers;
	}
	
	public Comparable[] generateRandomStrings(int naamInt){
		Comparable[] randomStrings = null;
		//some code to generate random strings
		return randomStrings;
	}
	
	private Comparable[] splice(Comparable[] compare){
		return compare;
	}
	
	private void sort(Comparable[] c) {
		try
		{
			String rmiObjectName = "rmi://" + HOST + "/sort";
			@SuppressWarnings("unused")
			ISortFactory rem = (ISortFactory)Naming.lookup(rmiObjectName);
			Comparable[][] splicedArray = splice(c);
			
			for(int i = 0; i < splicedArray.length; i++)
			{
				SorterThread st = new SorterThread(splicedArray[i]);
				st.addObserver(ListJoiner);
				Thread sortThread = new Thread(st);
				sortThread.setDaemon(false);
				sortThread.start();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	private void sort(){
		
	}
}
